#include "tablewidget.h"

TableWidget::TableWidget(const QStringList &headerNames, QWidget *parent) :
    QTableWidget(parent)
{
    setColumnCount(headerNames.size());
    setHorizontalHeaderLabels(headerNames);
    for (int i = 0;i < headerNames.length();++i) {
        horizontalHeader()->setResizeMode(i,QHeaderView::Stretch);
    }

    verticalHeader()->hide();
    setShowGrid(false);
}
void TableWidget::clearAllItems()
{
    int counter = rowCount();
    while(counter)
    {
        counter = counter - 1;
        removeRow(counter);
    }
}
void TableWidget::addItems(const QList<QTableWidgetItem *> &list)
{
    if (rowCount() > 30)  {
        clearAllItems();
    }
    int row = rowCount();
    insertRow(row);
    for (int i = 0;i < list.size();++i) {
        setItem(row,i,list.at(i));
    }
}
